package com.itheima_04;

public class MyThread extends Thread {
    private int ticket = 100;

    @Override
    public void run() {
        while (true){
            synchronized (MyThread.class) {//字节码文件唯一
                if (ticket > 0) {
                    System.out.println(Thread.currentThread().getName() + "在买票,还剩" + ticket + "张");
                    ticket--;
                } else {
                    break;
                }
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
